package com.wxproject.demo.Utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Utils {
    private static final String salt = "!@#&*%^#$#FAS+-=$##!$!%^*(Q!@#$()&#^*%@TASC";
    private static final String salt_1="\uF8F5\u0015$餓 嬋\uF8F5\u00154餓 P崊硷\uF8F5\uF8F5P??\uF8F5兡\fj j\u0001P崓";

    public static String code1(String str){
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update((salt+str+salt_1).getBytes());
            byte[]byteDigest = md.digest();
            int i;
            StringBuffer buf = new StringBuffer("");
            for (int offset = 0; offset < byteDigest.length; offset++) {
                i = byteDigest[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            //32位加密
            return buf.toString();
            // 16位的加密
            //return buf.toString().substring(8, 24);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static String code(String str){
        String s = code1(str);
        for (int i = 0; i <100 ; i++) {
            s = code1(s);
        }
        return s;
    }

    public static void main(String[] args) {
        code("12ASFFAFAGAWGAGAGAWGASDASFA3");
    }
}
